﻿using ActivateYourGlutes.Data;
using ActivateYourGlutes.Infrastructure;
using ActivateYourGlutes.Infrastructure.MembershipServices;
using ActivateYourGlutes.Services.Model;

namespace ActivateYourGlutes.Services.Implementation
{
    public class MembershipProviderBase<T> : ProviderBase<T> where T : class
    {
        protected IMembershipService MembershipService { get; private set; }

        protected MembershipProviderBase(IEntityModelFactory factory, IMembershipService service)
            : base(factory)
        {
            MembershipService = service;
        }

        protected void AuthorizeAccountAsAdministrator(Account accessingAccount)
        {
            if (!MembershipService.IsAdministrator(accessingAccount.Username))
                throw new AuthorizationException("You do not have rights to perform this function");
        }
    }
}
